package com.liangtian.mdm.base.utils;

import com.github.pagehelper.PageInfo;

import java.io.Serializable;

/**
 * <p>Encoding    :  UTF-8</p>
 * <p>Package Name: com.liangtian.mdm.base.utils </p>
 * <p>Project Name: dm </p>
 * <p>Copyright   :  Copyright(c) 2016 石化盈科信息技术有限责任公司 </p>
 * <p>Created Time: 2016-04-11 10:38</p>
 * <p>Description : 交易请求处理完成返回的javabean</p>
 *
 * @author : Administrator
 * @version :  1.0
 */
public class ResultObject implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success = true;
    private String msg;
    private String code = "200";
    private Object data;
    private boolean login = true;
    private Integer draw;
    private Long recordsTotal;
    private Long recordsFiltered;


    public ResultObject() {
    }

    public ResultObject(String msg) {
        this.msg = msg;
    }

    public ResultObject(Object data) {
        this.data = data;
    }

    public ResultObject(boolean result, String msg) {
        this.success = result;
        this.msg = msg;
    }

    public ResultObject(String msg, String code) {
        this.msg = msg;
        this.code = code;
    }

    /**
     * 新增、修改、删除 可使用返回构造方法;
     *
     * @param result     返回结果(1成功 0失败)
     * @param successMsg 成功消息
     * @param errMsg     失败消息
     */
    public ResultObject(Integer result, String successMsg, String errMsg) {
        if (result > 0) {
            this.msg = successMsg;
            this.code = errMsg;
        } else {
            this.msg = errMsg;
            this.success = false;
        }
        this.data = result;
    }

    /**
     * 新增、修改、删除返回构造方法(默认模板)
     *
     * @param result 返回结果(1成功 0失败)
     * @param msg    消息(只需填写业务名称,eg:角色/日志)
     */
    public ResultObject(Integer result, String msg) {
        if (result > 0) {
            this.msg = "操作" + msg + "成功";
        } else {
            this.msg = "操作" + msg + "失败";
            this.success = false;
        }
        this.data = result;
    }


    /**
     * 查询分页使用构造方法
     *
     * @param pageInfo 分页对象
     * @param draw     baseModel的draw,每个实体对象集成BaseModel
     */
    public ResultObject(PageInfo pageInfo, Integer draw) {
        if (null != pageInfo) {
            this.data = pageInfo.getList();
            this.draw = draw;
            this.recordsFiltered = pageInfo.getTotal();
            this.recordsTotal = pageInfo.getTotal();
        }
    }


    public boolean isLogin() {
        return this.login;
    }

    public void setLogin(boolean login) {
        this.login = login;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getDraw() {
        return this.draw;
    }

    public void setDraw(Integer draw) {
        this.draw = draw;
    }

    public Long getRecordsTotal() {
        return this.recordsTotal;
    }

    public void setRecordsTotal(Long recordsTotal) {
        this.recordsTotal = recordsTotal;
    }

    public Long getRecordsFiltered() {
        return this.recordsFiltered;
    }

    public void setRecordsFiltered(Long recordsFiltered) {
        this.recordsFiltered = recordsFiltered;
    }

    public String toString() {
        return "ResultObj{result=" + this.success + ", msg=" + this.msg + ", code=" + this.code + ", data=" + this.data + '}';
    }
}
